<?php
	//TuấnNK add (20090619_10h):
	//Xử lý cập nhật lại tỉnh thành phố:

	require_once 'core/Debug.php'; //System Debug...
	require_once 'core/config.php';//System Config...
	
	require_once ROOT_PATH.'core/CGlobal.php';
	require_once ROOT_PATH.'core/DB.php';
	
	//Khởi tạo các biến hệ thống:
	global $server_list;
	CGlobal::$my_server=$server_list;
	unset($server_list);
	
	if(MEMCACHE_ON)
	require_once ROOT_PATH.'core/AZMemcache.php';
	
	require_once ROOT_PATH.'core/AZLib.php';
	require_once ROOT_PATH.'core/AZArrCache.php';
	require_once ROOT_PATH.'core/System.php';
	require_once ROOT_PATH.'core/Url.php';
	
	// Disable ALL magic_quote
	set_magic_quotes_runtime(0);
	register_shutdown_function(array("DB","close"));
	
	$js_file = ROOT_PATH."javascript/enbac/cities.js";
	
	AZLib::getProvinces();
	
	echo "<pre>";
		print_r(CGlobal::$provinces);
		echo "</pre>";
	
	$cities = array();
		
	if(CGlobal::$provinces){
		foreach (CGlobal::$provinces as $City){	
			if($City['id']!=0){
				$tp = array(
							"id"			=> $City['id'],
							"url"			=> "tp{$City['id']}/{$City['ebname']}.html",
							"bdsurl"		=> "bds{$City['id']}/{$City['ebname']}.html",
							"name" 			=> $City['name']
							);
											
				if($City['status']=='HOME'){
					$cities['HOME'][] = $tp; 
				}
				else{
					if($City['area'] == 1){
						$cities['NORTHEN'][] = $tp; 
					}
					elseif($City['area'] == 2 ){
						$cities['MIDDLE'][] = $tp; 
					}
					elseif($City['area'] == 3 ){
						$cities['SOUTHEN'][] = $tp; 
					}
				}
			}
		}
	}
	
	file_put_contents($js_file,"cities_eb = ".json_encode($cities).";");
	echo "<br />Done!";
?>